package hotel.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.ResultSetExtractor;
import org.springframework.stereotype.Repository;

import hotel.dao.LoginDao;
import hotel.pojo.ManagerDto;

@Repository
public class LoginDaoImpl implements LoginDao {
	
	@Resource(name="mysqlJdbcTemplate")
	private JdbcTemplate jdbcTemplate;
	
	public List<ManagerDto> ManagerLogin(String id) {
		String sql = "SELECT * FROM manager WHERE num = ?";
		ResultSetExtractor<List<ManagerDto>> login = new ResultSetExtractor<List<ManagerDto>>() {
			public List<ManagerDto> extractData(ResultSet rs) throws SQLException, DataAccessException{
				List<ManagerDto> login = new ArrayList<ManagerDto>();
				while(rs.next()) {
					String num = rs.getString("num");
					String pass = rs.getString("pass");
					ManagerDto mangerDto = new ManagerDto(num,pass);
					login.add(mangerDto);
				}
				return login;
			}
		};	
		return jdbcTemplate.query(sql,new Object[] {id},login);
	}

}
